/*
This do file cleans and analyses Niger dataset for the year 2012
*/

set more off

//CRUCIAL - set path to working folder(point to where the dataset is located on your computer)

* rename variables
 ren v005 pweight
 ren v001 PSU
 ren v006 Month_intvw
 ren v007 Year_intvw
 ren v010 RBirth_Year
 ren v012 RCurrent_Age
 ren v013 RAge_group
 ren v106 Education_level
 ren v130 Religion
 ren v501 marital_status
 ren b4 Sex_of_child
 ren m70 Check_2mths
 ren b1 Cmonth_birth
 ren b2 Cyear_birth
 ren m15 Cplc_delivery
 ren h0 rcvd_OPV0
 ren h2 rcvd_BCG
 ren h3 rcvd_DTP1
 ren h4 rcvd_OPV1
 ren h5 rcvd_DTP2
 ren h6 rcvd_OPV2
 ren h7 rcvd_DTP3
 ren h8 rcvd_OPV3
 ren h9 rcvd_MEASLES
 ren v190 wealth_index
 ren h1 Health_card
 ren v467d Dstnc_hfcilty
 
 *generate age of the child in months (date of interview-date of birth of child) 
 
 gen agemonth= v008-b3
 
  *generate alive children children aged 12-23 months
 gen C_age=0
 replace C_age= 1 if agemonth >=12 & agemonth<=23
 
 *drop children <12 &>23 months
 drop if C_age ==0
 
 * drop dead children (remain with living children aged 12-23 months)
 drop if b5==0
 
*tell Stata the weight (using pweights for robust standard errors), cluster (psu), and strata:
svyset PSU [pw=PSU]


*****Generatng vaccinated or not by antigen**
gen bcg_vac=.
replace bcg_vac=0 if (rcvd_BCG==.|rcvd_BCG==0 | rcvd_BCG==3 | ///
rcvd_BCG==8 |rcvd_BCG==9) 
replace bcg_vac=1 if (rcvd_BCG==1|rcvd_BCG==2)
label define bcg_vac 0 "not vaccinated"  1 "vaccinated",modify
label values bcg_vac bcg_vac

gen dpt1_vac=.
replace dpt1_vac=0 if (rcvd_DTP1==.|rcvd_DTP1==0 | rcvd_DTP1==3 | ///
rcvd_DTP1==8 |rcvd_DTP1==9)
replace dpt1_vac=1 if (rcvd_DTP1==1|rcvd_DTP1==2)
label define dpt1_vac 0 "not vaccinated"  1 "vaccinated",modify
label values dpt1_vac dpt1_vac

gen dpt2_vac=.
replace dpt2_vac=0 if (rcvd_DTP2==.|rcvd_DTP2==0 | rcvd_DTP2==3 | ///
rcvd_DTP2==8 |rcvd_DTP2==9)
replace dpt2_vac=1 if (rcvd_DTP2==1|rcvd_DTP2==2)
label define dpt2_vac 0 "not vaccinated"  1 "vaccinated",modify
label values dpt2_vac dpt2_vac


gen dpt3_vac=.
replace dpt3_vac=0 if (rcvd_DTP3==.|rcvd_DTP3==0 | rcvd_DTP3==3 | ///
rcvd_DTP3==8 |rcvd_DTP3==9)
replace dpt3_vac=1 if (rcvd_DTP3==1|rcvd_DTP3==2)
label define dpt3_vac 0 "not vaccinated"  1 "vaccinated",modify
label values dpt3_vac dpt3_vac


gen opv0_vac=.
replace opv0_vac=0 if (rcvd_OPV0==.| rcvd_OPV0==0| rcvd_OPV0==3| ///
rcvd_OPV0==8| rcvd_OPV0==9)
replace opv0_vac=1 if (rcvd_OPV0==1| rcvd_OPV0==2)
label define opv0_vac 0 "not vaccinated"  1 "vaccinated",modify
label values opv0_vac opv0_vac


gen opv1_vac=.
replace opv1_vac=0 if (rcvd_OPV1==.| rcvd_OPV1==0| rcvd_OPV1==3| ///
rcvd_OPV1==8| rcvd_OPV1==9)
replace opv1_vac=1 if (rcvd_OPV1==1| rcvd_OPV1==2)
label define opv1_vac 0 "not vaccinated"  1 "vaccinated",modify
label values opv1_vac opv1_vac


gen opv2_vac=.
replace opv2_vac=0 if (rcvd_OPV2==.| rcvd_OPV2==0| rcvd_OPV2==3| ///
rcvd_OPV2==8| rcvd_OPV2==9)
replace opv2_vac=1 if (rcvd_OPV2==1| rcvd_OPV2==2)
label define opv2_vac 0 "not vaccinated"  1 "vaccinated",modify
label values opv2_vac opv2_vac


gen opv3_vac=.
replace opv3_vac=0 if (rcvd_OPV3==.| rcvd_OPV3==0| rcvd_OPV3==3| ///
rcvd_OPV3==8| rcvd_OPV3==9)
replace opv3_vac=1 if (rcvd_OPV3==1| rcvd_OPV3==2)
label define opv3_vac 0 "not vaccinated"  1 "vaccinated",modify
label values opv3_vac opv3_vac


gen measles_vac=.
replace measles_vac=0 if (rcvd_MEASLES==.|rcvd_MEASLES==0| ///
rcvd_MEASLES==3|rcvd_MEASLES==8|rcvd_MEASLES==9)
replace measles_vac=1 if (rcvd_MEASLES==1|rcvd_MEASLES==2)
label define measles_vac 0 "not vaccinated"  1 "vaccinated",modify
label values measles_vac measles_vac

******generating immunization status for only BCG, OPV1, OPV2, OPV3, DPT1, DPT2, DPT3 and Measles
gen immunization_status1=.
replace immunization_status1=0 if (bcg_vac==0& dpt1_vac==0& ///
dpt2_vac==0& dpt3_vac==0& opv1_vac==0& opv2_vac==0& opv3_vac==0& measles_vac==0)
replace immunization_status1=1 if (bcg_vac==1|dpt1_vac==1| ///
dpt2_vac==1|dpt3_vac==1|opv1_vac==1|opv2_vac==1|opv3_vac==1|measles_vac==1)
replace immunization_status1=2 if (bcg_vac==1 & dpt1_vac==1& ///
dpt2_vac==1& dpt3_vac==1& opv1_vac==1& opv2_vac==1& opv3_vac==1& measles_vac==1)
label define immunization_status1 0 "not immunized"  1 "partially immunized" 2 "fully immunized", modify
label values immunization_status1 immunization_status1

*****generate non- or under-immunized and fully immunized

gen immunization_status2=.
replace immunization_status2=0 if (immunization_status1==0 | immunization_status1==1)
replace immunization_status2=1 if (immunization_status1==2)
labe define immunization_status2 0 "non- or under-immunized" 1 "fully immunized"
label values immunization_status2 immunization_status2

*****vaccination coverage for each vaccine
tab bcg_vac [aweight=pweight]

tab dpt1_vac [aweight=pweight]

tab dpt2_vac [aweight=pweight]

tab dpt3_vac [aweight=pweight]

tab opv1_vac [aweight=pweight]

tab opv2_vac [aweight=pweight]

tab opv3_vac [aweight=pweight]

tab measles_vac [aweight=pweight]

******received all 8 vaccines
tab immunization_status1 [aweight=pweight]

tab immunization_status2 [aweight=pweight]

*****Independent factors
** 1. Child Sex
tab Sex_of_child [aweight=pweight]

***2. Mother's age group
 gen mthrage_grp=.
 replace mthrage_grp=0 if (RAge_group==1 | RAge_group==2)
 replace mthrage_grp=1 if (RAge_group==3)
 replace mthrage_grp=2 if (RAge_group==4 | RAge_group==5 | RAge_group==6 | RAge_group==7)
 label define mthrage_grp 0 "<=24" 1 "25-29" 2 ">=30"
 label values mthrage_grp mthrage_grp
 
 ***3. Mother's marital status
 gen mothr_maritalstats=.
 replace mothr_maritalstats=0 if (marital_status==0)
 replace mothr_maritalstats=1 if (marital_status==1 | marital_status==2)
 replace mothr_maritalstats=2 if (marital_status==3 | marital_status==4 | marital_status==5)
 label define  mothr_maritalstats 0 "Never married" 1 "Currently married" 2 "Formerly married"
 label values  mothr_maritalstats   mothr_maritalstats
 
 ***4. Mother's education level
gen mothr_education=.
replace mothr_education=0 if (Education_level==0)
replace mothr_education=1 if (Education_level==1)
replace mothr_education=2 if (Education_level==2 | Education_level==3)
label define mothr_education 0 "No education" 1 "Primary" 2 "Secondary/Higher"
label values mothr_education mothr_education


***5. socio-economic status/wealth index
 gen economic_status=.
 replace economic_status=0 if (wealth_index==1 | wealth_index==2)
 replace economic_status=1 if (wealth_index==3)
 replace economic_status=2 if (wealth_index==4| wealth_index==5)
 label define economic_status 0 "Poor" 1 "Middle" 2 "Rich"
 label values economic_status economic_status
 
 ***6. generate Rural residence  
 gen rural_residence=.
 replace rural_residence=0 if (v025==1)
 replace rural_residence=1 if (v025==2)
 label define rural_residence 0 "No/urban" 1 "yes/rural", modify
 label values rural_residence rural_residence
 
 ***7. Child' place of birth/delivery
 gen place_birth=.
 replace place_birth=0 if (Cplc_delivery==11 | Cplc_delivery==12 | Cplc_delivery==96)
 replace place_birth=1 if (Cplc_delivery==21 | Cplc_delivery==22 | Cplc_delivery==23 | Cplc_delivery==26 | Cplc_delivery==31 | Cplc_delivery==33)
 label define place_birth 0 "Home" 1 "Hospital/Health Facilities", modify
 label values place_birth place_birth
 
***8. child checkup within two months 
 gen check_2mths=.
 replace check_2mths=0 if (Check_2mths==0)
 replace check_2mths=1 if (Check_2mths==1)
 label define check_2mths 0 "Not checked " 1 "checked within 2months", modify
 label values check_2mths check_2mths
 ***9. Distance to health facility (big problem/not a big problem)
 gen distc_a_problm=.
 replace distc_a_problm=0 if Dstnc_hfcilty==2
 replace distc_a_problm=1 if Dstnc_hfcilty==1
 label define distc_a_problm 0 "no" 1 "yes"
 label values distc_a_problm distc_a_problm
 
 ***10. Birth order
gen birth_order=.
replace birth_order=0 if (bord==1)
replace birth_order=1 if (bord==2 | bord==3)
replace birth_order=2 if (bord>=4)
label define birth_order 0 "1" 1 "2/3" 2 ">=4"
label values birth_order birth_order
 
 ***13. generating with and without vaccination card
gen healthcard=.
replace healthcard=0 if (Health_card==0| Health_card==2| Health_card==3)
replace healthcard=1 if (Health_card==1)
label define healthcard 0 "without healthcard" 1 "with health card"
label values healthcard healthcard

tab healthcard [aweight=pweight]


**** generate county
gen Country="NIGER" 

keep PSU pweight b3 v008 v021 v022 v023 v024 v025 Sex_of_child Dstnc_hfcilty agemonth C_age ///
bcg_vac dpt1_vac dpt2_vac dpt3_vac opv0_vac opv1_vac opv2_vac ///
opv3_vac measles_vac immunization_status1 immunization_status2 mthrage_grp ///
mothr_maritalstats mothr_education economic_status rural_residence ///
place_birth check_2mths distc_a_problm birth_order ///
healthcard Country

 
****Univariate Analysis -(chi-square tests)

 *****Sex of the child
tab immunization_status2 Sex_of_child, row chi2

****Child has health card
tab immunization_status2 healthcard, row chi2

****Child's place of delivery
tab immunization_status2 place_birth, row chi2

****Child received checkup within 2 months after birth
tab immunization_status2 check_2mths, row chi2

****Child's birth order
tab immunization_status2 birth_order, row chi2

******Mother's marital status
tab immunization_status2 mothr_maritalstats, row chi2

*****Mother's education level
tab immunization_status2 mothr_education, row chi2

*****Mother's age group
tab immunization_status2 mthrage_grp, row chi2

***Economic status
tab immunization_status2 economic_status, row chi2

****Type of residence
tab immunization_status2 rural_residence, row chi2


**** Distance to health facility
tab immunization_status2 distc_a_problm, row chi2

****logistic regression accounting for clustering and weighting
	*****collinearity check***///
svy: regress immunization_status2 ///
healthcard ///
place_birth ///
check_2mths ///
i.birth_order ///
i.mothr_maritalstats ///
i.mothr_education ///
rural_residence ///
distc_a_problm
  
****Final model after backward removal of non significant variables
svy: logistic immunization_status2 ///
healthcard ///
check_2mths ///
distc_a_problm
